﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using YourWallet;

namespace yourwallet_test
{
    [TestClass]
    public class AccountsManagement_tests
    {
        AccountsManagement account_m;

        [TestInitialize]
        public void Initialize()
        {
            account_m = new AccountsManagement();
        }

        [TestMethod]
        public void AfterAddExpense_expenseListShouldntBeEmpty()
        {
            int month = 7;
            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            DateTime date = new DateTime(2013, month, 14);
            account_m.SetActiveDate(date);
            account_m.AddExpense(1000, "expense", date, "note");
            Assert.AreNotEqual(0, account_m.GetNumberOfTransactions());            
        }

        [TestMethod]
        public void AfterAddExpense_expenseListShouldBeEmptyOnDifferentAccount()
        {
            int month = 7;
            account_m.AddAccount("account1");
            account_m.SetActiveMonth();
            DateTime date = new DateTime(2013, month, 14);
            account_m.SetActiveDate(date);
            account_m.AddExpense(1000, "expense", date, "note");
            account_m.AddAccount("account2");
            Assert.AreEqual(0, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void AfterAddIncome_incomeListShouldntBeEmpty()
        {
            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            DateTime date = new DateTime(2013, 7, 14);
            account_m.SetActiveDate(date);
            account_m.AddIncome(1000, "income", date, "note");
            Assert.AreNotEqual(0, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void GetNumberOfTransactionsOfTheMonth_shouldReturnOnlyNumberOfTransactionsOfActiveMonth()
        {
            int numberOfExpenses = 2;
            int numberOfIncomes = 2;
            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2013, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add expense of another month than active
            account_m.AddExpense(1000, "expense", anotherDate, "note");

            //add income of another month than active
            account_m.AddIncome(1000, "income", anotherDate, "note");

            for (int i = 0; i < numberOfExpenses; ++i)
            {
                //add expenses of active month
                account_m.AddExpense(1000, "expense", activeDate, "note");
            }
            for (int i = 0; i < numberOfIncomes; ++i)
            {
                //add income of active month
                account_m.AddIncome(1000, "income", activeDate, "note");
            }

            Assert.AreNotEqual(activeDate, anotherDate);
            Assert.AreEqual(numberOfExpenses + numberOfIncomes, account_m.GetNumberOfTransactions());
        }
        
        [TestMethod]
        public void GetNumberOfTransactionsOfTheYear_shouldReturnOnlyNumberOfTransactionsOfActiveYear()
        {
            int numberOfExpenses = 2;
            int numberOfIncomes = 2;

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate);

            //add expense of another year than active
            account_m.AddExpense(1000, "expense", anotherDate, "note");

            //add income of another year than active
            account_m.AddIncome(1000, "income", anotherDate, "note");

            for (int i = 0; i < numberOfExpenses; ++i)
            {
                //add expenses of active year
                account_m.AddExpense(1000, "expense", activeDate, "note");
            }
            for (int i = 0; i < numberOfIncomes; ++i)
            {
                //add income of active year
                account_m.AddIncome(1000, "income", activeDate, "note");
            }

            Assert.AreNotEqual(activeDate, anotherDate);
            Assert.AreEqual(numberOfExpenses + numberOfIncomes, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void GetExpense_shouldReturnOnlyExpenseOfActiveMonth()
        {
            int numberOfExpenses = 2;
            double expense = 0;

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add expense of another month than active
            account_m.AddExpense(1000, "expense", anotherDate, "note");

            for (int i = 0; i < numberOfExpenses; ++i)
            {
                //add expenses of active month
                double amount = 1000;
                account_m.AddExpense(amount, "expense", activeDate, "note");
                expense += amount;
            }

            Assert.AreNotEqual(activeDate, anotherDate);
            Assert.AreEqual(expense, account_m.GetExpense());
        }

        [TestMethod]
        public void GetIncome_shouldReturnOnlyIncomeOfActiveMonth()
        {
            int numberOfExpenses = 2;
            double income = 0;

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add income of another month than active
            account_m.AddIncome(1000, "income", anotherDate, "note");

            for (int i = 0; i < numberOfExpenses; ++i)
            {
                //add income of active month
                double amount = 1000;
                account_m.AddIncome(amount, "income", activeDate, "note");
                income += amount;
            }

            Assert.AreNotEqual(activeDate, anotherDate);
            Assert.AreEqual(income, account_m.GetIncome());
        }

        [TestMethod]
        public void GetBalance_shouldReturnOnlyBalanceOfActiveMonth()
        {
            int numberOfExpenses = 2;
            double balance = 0;

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add income of another month than active
            account_m.AddIncome(10, "income", anotherDate, "note");

            //add expense of another month than active
            account_m.AddExpense(20, "expense", anotherDate, "note");

            for (int i = 0; i < numberOfExpenses; ++i)
            {
                //add income of active month
                double amount = 1000;
                account_m.AddIncome(amount, "income", activeDate, "note");
                balance += amount;
            }

            for (int i = 0; i < numberOfExpenses; ++i)
            {
                //add expenses of active month
                double amount = 100;
                account_m.AddExpense(amount, "expense", activeDate, "note");
                balance -= amount;
            }

            Assert.AreNotEqual(activeDate, anotherDate);
            Assert.AreEqual(balance, account_m.GetBalance());
        }

        [TestMethod]
        public void GetExpense_shouldReturnOnlyExpenseOfActiveYear()
        {
            int numberOfExpenses = 2;
            double expense = 0;

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate);

            //add expense of another year than active
            account_m.AddExpense(1000, "expense", anotherDate, "note");

            for (int i = 0; i < numberOfExpenses; ++i)
            {
                //add expenses of active year
                double amount = 1000;
                account_m.AddExpense(amount, "expense", activeDate, "note");
                expense += amount;
            }

            Assert.AreNotEqual(activeDate, anotherDate);
            Assert.AreEqual(expense, account_m.GetExpense());
        }

        [TestMethod]
        public void GetIncome_shouldReturnOnlyIncomeOfActiveYear()
        {
            int numberOfExpenses = 2;
            double income = 0;

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate);

            //add income of another year than active
            account_m.AddIncome(1000, "income", anotherDate, "note");

            for (int i = 0; i < numberOfExpenses; ++i)
            {
                //add income of active year
                double amount = 1000;
                account_m.AddIncome(amount, "income", activeDate, "note");
                income += amount;
            }

            Assert.AreNotEqual(activeDate, anotherDate);
            Assert.AreEqual(income, account_m.GetIncome());
        }

        [TestMethod]
        public void GetBalance_shouldReturnOnlyBalanceOfActiveYear()
        {
            int numberOfExpenses = 2;
            double balance = 0;

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate);

            //add income of another year than active
            account_m.AddIncome(10, "income", anotherDate, "note");

            //add expense of another year than active
            account_m.AddExpense(20, "expense", anotherDate, "note");

            for (int i = 0; i < numberOfExpenses; ++i)
            {
                //add income of active year
                double amount = 1000;
                account_m.AddIncome(amount, "income", activeDate, "note");
                balance += amount;
            }

            for (int i = 0; i < numberOfExpenses; ++i)
            {
                //add expenses of active year
                double amount = 100;
                account_m.AddExpense(amount, "expense", activeDate, "note");
                balance -= amount;
            }

            Assert.AreNotEqual(activeDate, anotherDate);
            Assert.AreEqual(balance, account_m.GetBalance());
        }

        //Accounts Names
        [TestMethod]
        public void GetAccountsNames_shouldReturnAccountsNames()
        {
            account_m.AddAccount("account1");
            account_m.AddAccount("account1");
            account_m.AddAccount("account2");

            Assert.AreEqual("account1", account_m.GetAccountsNames()[0]);
            Assert.AreEqual("account2", account_m.GetAccountsNames()[1]);

            Assert.AreEqual("account2", account_m.GetActiveAccount());
        }

        //Get Transactions Parameters
        [TestMethod]
        public void GetTransactionAmount_shouldReturnTransactionAmmountOfActiveMonth()
        {
            double amount1 = 1;
            double amount2 = 3;

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(amount1, "expense", activeDate, "note");
            //add income of another month than selected
            account_m.AddIncome(2, "income", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(amount2, "income", activeDate, "note");

            Assert.AreEqual(amount1, account_m.GetTransactionAmount(0));
            Assert.AreEqual(amount2, account_m.GetTransactionAmount(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void GetTransactionAmount_shouldReturnTransactionAmmountOfActiveYear()
        {
            double amount1 = 1;
            double amount2 = 3;

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate);

            //add expense of active year
            account_m.AddExpense(amount1, "expense", activeDate, "note");
            //add income of another year than selected
            account_m.AddIncome(2, "income", anotherDate, "note");
            //add income of active year
            account_m.AddIncome(amount2, "income", activeDate, "note");

            Assert.AreEqual(amount1, account_m.GetTransactionAmount(0));
            Assert.AreEqual(amount2, account_m.GetTransactionAmount(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
        }

        //Get Transaction Parameters
        [TestMethod]
        public void GetTransactionNote_shouldReturnTransactionNoteOfActiveMonth()
        {
            string note1 = "note1";
            string note2 = "note2";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, "expense", activeDate, note1);
            //add income of another month than selected
            account_m.AddIncome(1, "income", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(1, "income", activeDate, note2);

            Assert.AreEqual(note1, account_m.GetTransactionNote(0));
            Assert.AreEqual(note2, account_m.GetTransactionNote(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void GetTransactionNote_shouldReturnTransactionNoteOfActiveYear()
        {
            string note1 = "note1";
            string note2 = "note2";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, "expense", activeDate, note1);
            //add income of another month than selected
            account_m.AddIncome(1, "income", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(1, "income", activeDate, note2);

            Assert.AreEqual(note1, account_m.GetTransactionNote(0));
            Assert.AreEqual(note2, account_m.GetTransactionNote(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void GetTransactionName_shouldReturnTransactionNoteIfNoteExistsOfActiveMonth()
        {
            string note1 = "note1";
            string note2 = "note2";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, "expense", activeDate, note1);
            //add income of another month than selected
            account_m.AddIncome(1, "income", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(1, "income", activeDate, note2);

            Assert.AreEqual(note1, account_m.GetTransactionName(0));
            Assert.AreEqual(note2, account_m.GetTransactionName(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void GetTransactionName_shouldReturnTransactionCategoryIfNoteDoesntExistsOfActiveYear()
        {
            string category1 = "category1";
            string category2 = "category2";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, category1, activeDate, "");
            //add income of another month than selected
            account_m.AddIncome(1, "income", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(1, category2, activeDate, "");

            Assert.AreEqual(category1, account_m.GetTransactionName(0));
            Assert.AreEqual(category2, account_m.GetTransactionName(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void GetTransactionCategory_shouldReturnTransactionCategoryOfActiveMonth()
        {
            string category1 = "category1";
            string category2 = "category2";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, category1, activeDate, "note");
            //add income of another month than selected
            account_m.AddIncome(1, "category", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(1, category2, activeDate, "note");

            Assert.AreEqual(category1, account_m.GetTransactionCategory(0));
            Assert.AreEqual(category2, account_m.GetTransactionCategory(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void GetTransactionCategory_shouldReturnTransactionCategoryOfActiveYear()
        {
            string category1 = "category1";
            string category2 = "category2";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, category1, activeDate, "note");
            //add income of another month than selected
            account_m.AddIncome(1, "category", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(1, category2, activeDate, "note");

            Assert.AreEqual(category1, account_m.GetTransactionCategory(0));
            Assert.AreEqual(category2, account_m.GetTransactionCategory(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void GetTransactionAccountName_shouldReturnTransactionAccountNameOfActiveMonth()
        {
            string accountName1 = "accountName1";
            string accountName2 = "accountName2";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount(accountName1);
            account_m.AddAccount(accountName2);
            account_m.SetActiveAccount(accountName1);

            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, "category", activeDate, "note");
            //add income of another month than selected
            account_m.AddIncome(1, "category", anotherDate, "note");

            account_m.SetActiveAccount(accountName2);
            //add income of active month
            account_m.AddIncome(1, "category", activeDate, "note");

            account_m.SetActiveAccount(accountName1);
            Assert.AreEqual(accountName1, account_m.GetTransactionAccountName(0));
            Assert.AreEqual(1, account_m.GetNumberOfTransactions());
            account_m.SetActiveAccount(accountName2);
            Assert.AreEqual(accountName2, account_m.GetTransactionAccountName(0));
            Assert.AreEqual(1, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void GetTransactionAccountName_shouldReturnTransactionAccountNameOfActiveYear()
        {
            string accountName1 = "accountName1";
            string accountName2 = "accountName2";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount(accountName1);
            account_m.AddAccount(accountName2);
            account_m.SetActiveAccount(accountName1);
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate);

            //add expense of active year
            account_m.AddExpense(1, "category", activeDate, "note");
            //add income of another year than selected
            account_m.AddIncome(1, "category", anotherDate, "note");

            account_m.SetActiveAccount(accountName2);
            //add income of active year
            account_m.AddIncome(1, "category", activeDate, "note");

            account_m.SetActiveAccount(accountName1);
            Assert.AreEqual(accountName1, account_m.GetTransactionAccountName(0));
            Assert.AreEqual(1, account_m.GetNumberOfTransactions());
            account_m.SetActiveAccount(accountName2);
            Assert.AreEqual(accountName2, account_m.GetTransactionAccountName(0));
            Assert.AreEqual(1, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void GetTransactionDate_shouldReturnTransactionDateOfActiveMonth()
        {
            DateTime activeDate1 = new DateTime(2013, 7, 1);
            DateTime activeDate2 = new DateTime(2013, 7, 3);
            DateTime anotherDate2 = new DateTime(2012, 7, 2);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate1);

            //add expense of active month
            account_m.AddExpense(1, "expense", activeDate1, "note");
            //add income of another month than selected
            account_m.AddIncome(1, "income", anotherDate, "note");
            //add income of active month but another year
            account_m.AddIncome(1, "income", anotherDate2, "note");
            //add expense of active month
            account_m.AddIncome(1, "income", activeDate2, "note");

            Assert.AreEqual(activeDate1, account_m.GetTransactionDate(0));
            Assert.AreEqual(activeDate2, account_m.GetTransactionDate(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void GetTransactionDate_shouldReturnTransactionDateOfActiveYear()
        {
            int activeYear = 2013;
            int anotherYear = 2012;

            DateTime activeDate1 = new DateTime(activeYear, 6, 1);
            DateTime activeDate2 = new DateTime(activeYear, 7, 2);
            DateTime anotherDate = new DateTime(anotherYear, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate1);

            //add expense of active month
            account_m.AddExpense(1, "expense", activeDate1, "note");
            //add income of another month than selected
            account_m.AddIncome(1, "income", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(1, "income", activeDate2, "note");

            Assert.AreEqual(activeDate1, account_m.GetTransactionDate(0));
            Assert.AreEqual(activeDate2, account_m.GetTransactionDate(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
        }

        
        //Set Transaction Parameters
        [TestMethod]
        public void SetTransactionNote_shouldChangeTransactionNoteOfActiveMonth()
        {
            string note1 = "note1";
            string note2 = "note2";
            string new_note = "new_note";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, "expense", activeDate, note1);
            //add income of another month than selected
            account_m.AddIncome(1, "income", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(1, "income", activeDate, note2);

            Assert.AreEqual(note1, account_m.GetTransactionNote(0));
            Assert.AreEqual(note2, account_m.GetTransactionNote(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
            account_m.SetTransactionNote(1, new_note);
            Assert.AreEqual(new_note, account_m.GetTransactionNote(1));
        }

        [TestMethod]
        public void SetTransactionNote_shouldChangeTransactionNoteOfActiveYear()
        {
            string note1 = "note1";
            string note2 = "note2";
            string new_note = "new_note";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, "expense", activeDate, note1);
            //add income of another month than selected
            account_m.AddIncome(1, "income", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(1, "income", activeDate, note2);

            Assert.AreEqual(note1, account_m.GetTransactionNote(0));
            Assert.AreEqual(note2, account_m.GetTransactionNote(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
            account_m.SetTransactionNote(1, new_note);
            Assert.AreEqual(note1, account_m.GetTransactionNote(0));
            Assert.AreEqual(new_note, account_m.GetTransactionNote(1));
        }

        [TestMethod]
        public void SetTransactionCategory_shouldChangeTransactionCategoryOfActiveMonth()
        {
            string category1 = "category1";
            string category2 = "category2";
            string new_category = "new_category";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, category1, activeDate, "note");
            //add income of another month than selected
            account_m.AddIncome(1, "category", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(1, category2, activeDate, "note");

            Assert.AreEqual(category1, account_m.GetTransactionCategory(0));
            Assert.AreEqual(category2, account_m.GetTransactionCategory(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
            account_m.SetTransactionCategory(1, new_category);
            Assert.AreEqual(category1, account_m.GetTransactionCategory(0));
            Assert.AreEqual(new_category, account_m.GetTransactionCategory(1));
        }

        [TestMethod]
        public void SetTransactionCategory_shouldChangeTransactionCategoryOfActiveYear()
        {
            string category1 = "category1";
            string category2 = "category2";
            string new_category = "new_category";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, category1, activeDate, "note");
            //add income of another month than selected
            account_m.AddIncome(1, "category", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(1, category2, activeDate, "note");

            Assert.AreEqual(category1, account_m.GetTransactionCategory(0));
            Assert.AreEqual(category2, account_m.GetTransactionCategory(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
            account_m.SetTransactionCategory(1, new_category);
            Assert.AreEqual(category1, account_m.GetTransactionCategory(0));
            Assert.AreEqual(new_category, account_m.GetTransactionCategory(1));
        }

        [TestMethod]
        public void SetTransactionAccountName_shouldChangeTransactionAccountNameOfActiveMonth()
        {
            string accountName1 = "accountName1";
            string accountName2 = "accountName2";
            string new_accountName = "new_accountName";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount(accountName1);
            account_m.AddAccount(accountName2);
            account_m.AddAccount(new_accountName);
            account_m.SetActiveAccount(accountName1);

            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, "category", activeDate, "note");
            //add income of another month than selected
            account_m.AddIncome(1, "category", anotherDate, "note");

            account_m.SetActiveAccount(accountName2);
            //add income of active month
            account_m.AddIncome(1, "category", activeDate, "note");

            account_m.SetActiveAccount(accountName1);
            Assert.AreEqual(accountName1, account_m.GetTransactionAccountName(0));
            Assert.AreEqual(1, account_m.GetNumberOfTransactions());
            account_m.SetActiveAccount(accountName2);
            Assert.AreEqual(accountName2, account_m.GetTransactionAccountName(0));
            Assert.AreEqual(1, account_m.GetNumberOfTransactions());
            account_m.SetTransactionAccountName(0, new_accountName);
            account_m.SetActiveAccount(new_accountName);
            Assert.AreEqual(new_accountName, account_m.GetTransactionAccountName(0));
        }

        [TestMethod]
        public void SetTransactionAccountName_shouldntChangeTransactionAccountNameOfActiveMonthIfAccountDoesntExists()
        {
            string accountName1 = "accountName1";
            string accountName2 = "accountName2";
            string new_accountName = "new_accountName";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount(accountName1);
            account_m.AddAccount(accountName2);
            account_m.SetActiveAccount(accountName1);

            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, "category", activeDate, "note");
            //add income of another month than selected
            account_m.AddIncome(1, "category", anotherDate, "note");

            account_m.SetActiveAccount(accountName2);
            //add income of active month
            account_m.AddIncome(1, "category", activeDate, "note");

            account_m.SetActiveAccount(accountName1);
            Assert.AreEqual(accountName1, account_m.GetTransactionAccountName(0));
            Assert.AreEqual(1, account_m.GetNumberOfTransactions());
            account_m.SetActiveAccount(accountName2);
            Assert.AreEqual(accountName2, account_m.GetTransactionAccountName(0));
            Assert.AreEqual(1, account_m.GetNumberOfTransactions());
            account_m.SetTransactionAccountName(0, new_accountName);
            account_m.SetActiveAccount(new_accountName);
            Assert.AreEqual(accountName2, account_m.GetTransactionAccountName(0));
        }

        [TestMethod]
        public void SetTransactionAccountName_shouldChangeTransactionAccountNameOfActiveYear()
        {
            string accountName1 = "accountName1";
            string accountName2 = "accountName2";
            string new_accountName = "new_accountName";
            account_m.AddAccount(new_accountName);

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount(accountName1);
            account_m.AddAccount(accountName2);
            account_m.SetActiveAccount(accountName1);
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate);

            //add expense of active year
            account_m.AddExpense(1, "category", activeDate, "note");
            //add income of another year than selected
            account_m.AddIncome(1, "category", anotherDate, "note");

            account_m.SetActiveAccount(accountName2);
            //add income of active year
            account_m.AddIncome(1, "category", activeDate, "note");

            account_m.SetActiveAccount(accountName1);
            Assert.AreEqual(accountName1, account_m.GetTransactionAccountName(0));
            Assert.AreEqual(1, account_m.GetNumberOfTransactions());
            account_m.SetActiveAccount(accountName2);
            Assert.AreEqual(accountName2, account_m.GetTransactionAccountName(0));
            Assert.AreEqual(1, account_m.GetNumberOfTransactions());
            account_m.SetTransactionAccountName(0, new_accountName);
            account_m.SetActiveAccount(new_accountName);
            Assert.AreEqual(new_accountName, account_m.GetTransactionAccountName(0));
        }

        [TestMethod]
        public void SetTransactionDate_shouldChangeTransactionDateOfActiveMonth()
        {
            int activeMonth = 7;
            int anotherMonth = 8;

            DateTime activeDate1 = new DateTime(2013, activeMonth, 1);
            DateTime activeDate2 = new DateTime(2013, activeMonth, 2);
            DateTime new_date = new DateTime(2013, activeMonth, 3);
            DateTime anotherDate = new DateTime(2012, anotherMonth, 14);

            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate1);

            //add expense of active month
            account_m.AddExpense(1, "expense", activeDate1, "note");
            //add income of another month than selected
            account_m.AddIncome(1, "income", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(1, "income", activeDate2, "note");

            Assert.AreEqual(activeDate1, account_m.GetTransactionDate(0));
            Assert.AreEqual(activeDate2, account_m.GetTransactionDate(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
            account_m.SetTransactionDate(1, new_date);
            Assert.AreEqual(activeDate1, account_m.GetTransactionDate(0));
            Assert.AreEqual(new_date, account_m.GetTransactionDate(1));
        }

        [TestMethod]
        public void SetTransactionDate_shouldChangeTransactionDateOfActiveYear()
        {
            int activeYear = 2013;
            int anotherYear = 2012;

            DateTime activeDate1 = new DateTime(activeYear, 6, 1);
            DateTime activeDate2 = new DateTime(activeYear, 7, 2);
            DateTime new_date = new DateTime(activeYear, 5, 3);
            DateTime anotherDate = new DateTime(anotherYear, 4, 14);

            account_m.AddAccount("account");
            account_m.SetActiveYear();
            account_m.SetActiveDate(activeDate1);

            //add expense of active month
            account_m.AddExpense(1, "expense", activeDate1, "note");
            //add income of another month than selected
            account_m.AddIncome(1, "income", new DateTime(anotherYear, 7, 14), "note");
            //add income of active month
            account_m.AddIncome(1, "income", activeDate2, "note");

            Assert.AreEqual(activeDate1, account_m.GetTransactionDate(0));
            Assert.AreEqual(activeDate2, account_m.GetTransactionDate(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
            account_m.SetTransactionDate(1, new_date);
            Assert.AreEqual(activeDate1, account_m.GetTransactionDate(0));
            Assert.AreEqual(new_date, account_m.GetTransactionDate(1));
        }

        //Delete Transaction
        [TestMethod]
        public void DeleteTransaction_shouldDeleteTransactionOfActiveMonth()
        {
            string note1 = "note1";
            string note2 = "note2";

            DateTime activeDate = new DateTime(2013, 7, 14);
            DateTime anotherDate = new DateTime(2012, 8, 14);

            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            account_m.SetActiveDate(activeDate);

            //add expense of active month
            account_m.AddExpense(1, "expense", activeDate, note1);
            //add income of another month than selected
            account_m.AddIncome(1, "income", anotherDate, "note");
            //add income of active month
            account_m.AddIncome(1, "income", activeDate, note2);

            Assert.AreEqual(note1, account_m.GetTransactionNote(0));
            Assert.AreEqual(note2, account_m.GetTransactionNote(1));
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
            account_m.DeleteTransaction(0);
            Assert.AreEqual(note2, account_m.GetTransactionNote(0));
            Assert.AreEqual(1, account_m.GetNumberOfTransactions());
        }

        [TestMethod]
        public void AfterChangeInterval_activeDateShouldBeToday()
        {
            account_m.AddAccount("account");
            Assert.AreEqual(account_m.GetActiveDate(), DateTime.Today);
            account_m.SetActiveMonth();
            Assert.AreEqual(account_m.GetActiveDate(), DateTime.Today);
            account_m.IncreaseDate();
            account_m.SetActiveYear();
            Assert.AreEqual(account_m.GetActiveDate(), DateTime.Today);
            account_m.IncreaseDate();
        }

        [TestMethod]
        public void AfterIncreaseMonthOnDecember_activeDateShouldBeJanuaryNextYear()
        {
            int year = 2013;
            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            Assert.AreEqual(account_m.GetActiveDate(), DateTime.Today);
            account_m.SetActiveDate(new DateTime(year, 12, 1));
            account_m.IncreaseDate();
            Assert.AreEqual(1, account_m.GetActiveDate().Month);
            Assert.AreEqual(year + 1, account_m.GetActiveDate().Year);
        }

        [TestMethod]
        public void AfterDecreaseMonthOnJanuary_activeDateShouldBeDecemberLastYear()
        {
            int year = 2013;
            account_m.AddAccount("account");
            account_m.SetActiveMonth();
            Assert.AreEqual(account_m.GetActiveDate(), DateTime.Today);
            account_m.SetActiveDate(new DateTime(year, 1, 1));
            account_m.DecreaseDate();
            Assert.AreEqual(12, account_m.GetActiveDate().Month);
            Assert.AreEqual(year - 1, account_m.GetActiveDate().Year);
        }

        [TestMethod]
        public void AfterIncreaseYear_activeDateShouldBeNextYear()
        {
            int year = 2013;
            account_m.AddAccount("account");
            account_m.SetActiveYear();
            Assert.AreEqual(account_m.GetActiveDate(), DateTime.Today);
            account_m.SetActiveDate(new DateTime(year, 12, 1));
            account_m.IncreaseDate();
            Assert.AreEqual(year + 1, account_m.GetActiveDate().Year);
        }

        [TestMethod]
        public void AfterDecreaseYear_activeDateShouldBeLastYear()
        {
            int year = 2013;
            account_m.AddAccount("account");
            account_m.SetActiveYear();
            Assert.AreEqual(account_m.GetActiveDate(), DateTime.Today);
            account_m.SetActiveDate(new DateTime(year, 12, 1));
            account_m.DecreaseDate();
            Assert.AreEqual(year - 1, account_m.GetActiveDate().Year);
        }

        [TestMethod]
        public void IsIncome_IsExpense()
        {
            account_m.AddAccount("account");
            account_m.SetActiveYear();

            //add income of another year than active
            account_m.AddIncome(1000, "income", DateTime.Today, "note");
            account_m.AddExpense(1000, "expense", DateTime.Today, "note");

            Assert.AreEqual(true, account_m.IsIncome(0));
            Assert.AreEqual(false, account_m.IsExpense(0));
            Assert.AreEqual(false, account_m.IsIncome(1));
            Assert.AreEqual(true, account_m.IsExpense(1));                
        }

        [TestMethod]
        public void SetTransactionType()
        {
            account_m.AddAccount("account");
            account_m.SetActiveYear();

            //add income of another year than active
            account_m.AddIncome(1000, "income", DateTime.Today, "note");

            Assert.AreEqual(true, account_m.IsIncome(0));
            Assert.AreEqual(false, account_m.IsExpense(0));
            account_m.SetTransactionType(0, TransactionType.Expense);
            Assert.AreEqual(false, account_m.IsIncome(0));
            Assert.AreEqual(true, account_m.IsExpense(0));
        }

        [TestMethod]
        public void SetTransactionParameters_shouldChangeParametersOfTransaction()
        {
            string account = "account";
            string new_account = "new_account";

            account_m.AddAccount(account);
            account_m.AddAccount(new_account);
            account_m.SetActiveAccount(account);
            account_m.SetActiveYear();

            double amount = 1;
            double new_amount = 2;

            string category = "income";
            string new_category = "new_income";

            DateTime date = new DateTime(2012, 1, 1);
            DateTime new_date = new DateTime(2013, 2, 2);

            string note = "note";
            string new_note = "new note";

            account_m.SetActiveDate(date);
            //add income
            account_m.AddIncome(amount, category, date, note);

            Assert.AreNotEqual(new_account, account);
            Assert.AreNotEqual(new_amount, amount);
            Assert.AreNotEqual(new_category, category);
            Assert.AreNotEqual(new_date, date);
            Assert.AreNotEqual(new_note, note);

            Assert.AreEqual(true, account_m.IsIncome(0));
            Assert.AreEqual(account, account_m.GetTransactionAccountName(0));
            Assert.AreEqual(amount, account_m.GetTransactionAmount(0));
            Assert.AreEqual(category, account_m.GetTransactionCategory(0));
            Assert.AreEqual(date, account_m.GetTransactionDate(0));
            Assert.AreEqual(note, account_m.GetTransactionNote(0));

            account_m.SetTransactionParameters(0, new_account, new_amount, new_category,
                new_date, new_note, TransactionType.Expense);
            
            account_m.SetActiveDate(new_date);
            account_m.SetActiveAccount(new_account);
            Assert.AreEqual(true, account_m.IsExpense(0));
            Assert.AreEqual(new_account, account_m.GetTransactionAccountName(0));
            Assert.AreEqual(new_amount, account_m.GetTransactionAmount(0));
            Assert.AreEqual(new_category, account_m.GetTransactionCategory(0));
            Assert.AreEqual(new_date, account_m.GetTransactionDate(0));
            Assert.AreEqual(new_note, account_m.GetTransactionNote(0));
        }

        [TestMethod]
        public void GetAllTransactions()
        {
            string account = "account";
            account_m.AddAccount(account);
            int number_of_transactions = 4;

            account_m.AddIncome(1, "c1", new DateTime(2009, 1, 1), "n1");
            account_m.AddIncome(2, "c1", new DateTime(2010, 2, 2), "n1");
            account_m.AddExpense(3, "c1", new DateTime(2011, 3, 3), "n1");
            account_m.AddExpense(4, "c1", new DateTime(2012, 4, 4), "n1");

            Assert.AreEqual(number_of_transactions, account_m.GetAllTransations().Count);
        }

        [TestMethod]
        public void Generating_and_reading_xml()
        {
            string account = "account";
            account_m.AddAccount(account);
            Transaction t1 = new Transaction(account, 1, "c1", new DateTime(2009, 1, 1), "n1", TransactionType.Income);
            Transaction t2 = new Transaction(account, 2, "c2", new DateTime(2010, 2, 2), "n2", TransactionType.Income);
            Transaction t3 = new Transaction(account, 3, "c3", new DateTime(2011, 3, 3), "", TransactionType.Expense);
            Transaction t4 = new Transaction(account, 4, "c4", new DateTime(2012, 4, 4), "n4", TransactionType.Expense);

            account_m.AddIncome(t1.GetAmount(), t1.GetCategory(), t1.GetDate(), t1.GetNote());
            account_m.AddIncome(t2.GetAmount(), t2.GetCategory(), t2.GetDate(), t2.GetNote());
            account_m.AddExpense(t3.GetAmount(), t3.GetCategory(), t3.GetDate(), t3.GetNote());
            account_m.AddExpense(t4.GetAmount(), t4.GetCategory(), t4.GetDate(), t4.GetNote());

            XMLManagement xml = new XMLManagement();
            xml.WriteXML(account_m.GetAllTransations());
            List<Transaction> xmlTransactions = xml.ReadXML();

            Assert.AreEqual(account_m.GetAllTransations().Count, xmlTransactions.Count);
            Assert.AreEqual(t1.GetAmount(), xmlTransactions[0].GetAmount());
            Assert.AreEqual(t1.GetCategory(), xmlTransactions[0].GetCategory());
            Assert.AreEqual(t1.GetDate(), xmlTransactions[0].GetDate());
            Assert.AreEqual(t1.GetNote(), xmlTransactions[0].GetNote());
            Assert.AreEqual(true, xmlTransactions[0].IsIncome());

            Assert.AreEqual(t2.GetAmount(), xmlTransactions[1].GetAmount());
            Assert.AreEqual(t2.GetCategory(), xmlTransactions[1].GetCategory());
            Assert.AreEqual(t2.GetDate(), xmlTransactions[1].GetDate());
            Assert.AreEqual(t2.GetNote(), xmlTransactions[1].GetNote());
            Assert.AreEqual(true, xmlTransactions[1].IsIncome());

            Assert.AreEqual(t3.GetAmount(), xmlTransactions[2].GetAmount());
            Assert.AreEqual(t3.GetCategory(), xmlTransactions[2].GetCategory());
            Assert.AreEqual(t3.GetDate(), xmlTransactions[2].GetDate());
            Assert.AreEqual(t3.GetNote(), xmlTransactions[2].GetNote());
            Assert.AreEqual(true, xmlTransactions[2].IsExpense());

            Assert.AreEqual(t4.GetAmount(), xmlTransactions[3].GetAmount());
            Assert.AreEqual(t4.GetCategory(), xmlTransactions[3].GetCategory());
            Assert.AreEqual(t4.GetDate(), xmlTransactions[3].GetDate());
            Assert.AreEqual(t4.GetNote(), xmlTransactions[3].GetNote());
            Assert.AreEqual(true, xmlTransactions[3].IsExpense());
        }

        [TestMethod]
        public void AddTransactions()
        {
            string account = "account"; 
            DateTime date = new DateTime(2012, 1, 1);
            account_m.AddAccount(account);
            account_m.SetActiveYear();
            account_m.SetActiveDate(date);

            List<Transaction> trans = new List<Transaction>();
            trans.Add(new Transaction(account, 1, "c1", new DateTime(2012, 2, 1), "n1", TransactionType.Income));
            trans.Add(new Transaction(account, 2, "c2", new DateTime(2012, 1, 1), "n2", TransactionType.Expense));
            trans.Add(new Transaction(account, 3, "c3", new DateTime(2012, 2, 1), "n3", TransactionType.Income));
            trans.Add(new Transaction(account, 4, "c4", new DateTime(2012, 1, 1), "n4", TransactionType.Expense));

            account_m.AddTransactions(trans);
            Assert.AreEqual(4, account_m.GetNumberOfTransactions());
            account_m.SetActiveMonth();
            account_m.SetActiveDate(date);
            Assert.AreEqual(2, account_m.GetNumberOfTransactions());
        }
    }
}
